package com.jyy.server.controller;


import com.jyy.server.pojo.RespBean;
import com.jyy.server.pojo.Salary;
import com.jyy.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jyy
 * @since 2021-09-21
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;


    @ApiOperation(value = "获取所有工资套账")
    @GetMapping("/")
    public Object findAllSalary() {
        List<Salary> allSalary = salaryService.list();
        return allSalary;
    }

    @ApiOperation(value = "增加工资套账")
    @PostMapping("/add")
    public RespBean addSalary(@RequestBody Salary salary) {
        salary.setCreateDate(LocalDateTime.now());
        salaryService.save(salary);
        return RespBean.success("添加成功");
    }

    @ApiOperation(value = "修改工资套账")
    @PutMapping("/update")
    public RespBean updateSalary(@RequestBody Salary salary) {
        salaryService.updateById(salary);
        return RespBean.success("修改成功");
    }

    @ApiOperation(value = "删除工资套账")
    @DeleteMapping("/delete/{id}")
    public RespBean deleteSalary(@PathVariable("id") Integer id) {
        salaryService.removeById(id);
        return RespBean.success("删除成功");
    }
}
